﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System;
using Styx.Plugins;
using Styx.WoWInternals.WoWObjects;
using Styx;
using Styx.WoWInternals;
using Styx.Common;
using System.Windows.Media;

namespace Fragments
{

    public class Fragments : HBPlugin
    {
        public override string Name { get { return "Fragment User"; } }
        public override string Author { get { return "Celisuis";  } }
        public override Version Version { get { return new Version(0, 1);  } }
        public static LocalPlayer Me = StyxWoW.Me;
        
        // Array item ids
        public static uint[] itemIds = new uint[] {97622, 97621, 97620, 9761, 97623, 97624, 97512, 97546, 97619}; 
        
        // A delay for a smooth process, why so much rush?
		public static int delay = 2;
        public DateTime cur = DateTime.Now.AddSeconds(delay);

        public override void Pulse()
        {
        	//Some verification
			if (Me == null || !StyxWoW.IsInGame || Me.IsDead || Me.IsGhost || Battlegrounds.IsInsideBattleground || Me.IsInInstance || Me.IsOnTransport)
				return;
			//Not casting or in combat
			if (Me.IsCasting || Me.IsActuallyInCombat)
				return;
			
			// 2 sec delay, for a smooth process
        	if(DateTime.Now > cur)
        	{
        		var items = Me.BagItems.Where(x => itemIds.Contains(x.Entry) && x.Cooldown == 0 && x.StackCount > 10 );
	        	if(items.Count() > 0)
	        		items.First().Use();
	        	cur = DateTime.Now.AddSeconds(delay);
        	}
        }
    }
}